package org.huangrui.spark.scala.core.rdd.operate

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author hr
 * @Create 2024-10-17 1:58 
 */
object Spark04_Operate_Transform_FlatMap {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("spark")
    val sc = new SparkContext(conf)
    val datas = List(List(1, 2), List(3, 4))
    val rdd = sc.parallelize(datas, 2)

    // TODO RDD的转换方法：flatmap (扁平映射)
    //      flat(数据扁平化) + map(映射)
    val flatMapRdd = rdd.flatMap((x: List[Int]) => x.map((y: Int) => y * 2))

    flatMapRdd.collect().foreach(println)
    sc.stop()
  }
}
